home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
TAWUG
/
TAWUG Disk No. 66 (SHK)
/
TAWUG66.shk
/
ASSEMBLY.LANG.1
(
.txt
)
< prev
next >
Wrap
AppleWorks Document
|
1988-03-11
|
11KB
|
177 lines
O=====|====|====|====|====|====|====|====|====|====|====|====|====|====|====|===
NOTE: This file was downloaded from a Denver bulletin board.
Learning Apple 65C02 Assembly Language - Session one
Some thoughts about this "class."E
CI am hoping that folks will participate in this class by doing the
following:;
1) download the "class notes." (This file is session one)B
@2) Send me email telling me that you downloaded (I am active as )
"niemannross" on CACHE (303) 745-4960.)I
G3) Read the file, try some things and participate in the discussion on G
Ethe bbs. You will probably find it under board #4, basic programming
as a subtopic.
GOnce again, this is an experiment. Let me know if you like it, and how 3
it can be improved. And now...on with the show!!!
WHY WOULD ANYONE WANT TO DO THINGS THE HARD WAY?
FLet's face it. Assembly language is unfriendly, cryptic, difficult to I
Guse and just one more !*^&$#! thing to learn. Why bother? Why not just H
Fdwell in the land of Applesloth (applesoft - ha ha) forever and leave H
Fthis machine language stuff to insomniacs with poor social skills? In F
Dfact, my father has a Franklin Ace 1000 and would rather backup his A
?entire collection of software onto cassette tapes than program F
Danything in assembly. It's ok. Dad's a nice guy and puts up with my H
Fpeculiarities. But before you agree with him and trash this download, G
Elet's examine two good reasons why assembly language really isn't so
evil.
! Speed !H
FDad and I argue about this all the time. He says BASIC is faster, and I
GI say assm (short for assembly language, ok?) is. Actually, I'll admit D
Bhe is right in a way. It is faster to PROGRAM an application in a G
Ehigher level language such as BASIC. That's why languages exist. But H
Fif you've got to do something that requires runtime speed, folks, you H
Fcan either fork over $200 for an accelerator board or you can program F
Din assm. True, you can optimize BASIC, even compile it, but you are H
Fonly trying to achieve the speed that assm takes for granted. Now, it I
Gis possible to program a sloppy mess in assm that takes 5 working days I
Gto run, but avoiding that is reasonably easy, and probably easier than E
Ctrying to optimize an applesloth program. And try to write a music >
<subroutine in applesloth without resorting to a ml (another .
abbreviation...Machine Language) subroutine!
! Access !G
EA main factor for programming a byte at a time is the access allowed B
@to the machine itself. If you are going to try interfacing to a H
Fnon-standard chunk of hardware, add something to the operating system H
F(such as a new command for BASIC) or do anything that requires access E
Cto machine addresses and such, your task is actually simplified by ?
=using assm. Imagine trying to write a disk driver routine in E
Capplesloth. Sure, not an everyday task. But using assm reduces the F
Dtask to a manageable level SIMPLY BECAUSE WE DON'T HAVE TO OUTGUESS G
ESOMEBODY ELSE'S PROGRAM, a program such as the BASIC interpreter. If H
Fyou have to get a direct value from an address in basic, you PEEK and G
Ehope that none of the code related to PEEK changes anything that you G
Eneed to use. In assm, we perform one operation and know EXACTLY what /
is going on and if anything has been changed.
EOk, enough of that. If you're still reading, then you don't need any G
Emore justifications for learning this thing. Great. Now, here's what
you should do next.
?1) Buy a good reference book on 65C02. There's bunches of them B
@everywhere. When you look, make sure that the book you pick out A
?explains each of the commands in detail in a way that you feel H
Fcomfortable with. Don't worry if you don't understand everything they I
Gare talking about, that just means that you will be able to learn more I
Gfrom it. Buy one on assembly language, and buy the technical reference H
Fmanual for the particular computer you are using. Be aware that there ,
ARE different manuals for the //e and //c.
D (Note: my apologies to you 65816 types out there. I am directing H
Fthis class towards the 6502 and 65C02. Actually, this is still a good C
Aplace to start for 65816, as the 6502 and 65C02 command sets are
subsets to 65816.)
B2) Do yourself (and me) a favor and purchase an "assembler." This I
Gsoftware will allow you to write and edit programs in a clear fashion, F
Dtakes a lot of the grunt work out of programming assm and will make G
Eyour family much happier. I will be using Merlin PRO, available from F
Dyour local apple dealer or from Roger Wagner Publishing, Inc. 10761 I
GWoodside Ave, Suite E, Santee, California 92071. Other suggestions are G
Eapple's own edasm, Orca/M or Orca/EZ, and a gaggle of others. If you G
Ehave questions, bounce them off of the bbs and we'll try to get some *
feedback on what's the best one for you.
EIf you have any notion about trying to poke code in by hand or about G
Eusing the mini-assembler, please re-think. There are a LOT of things 5
that neither of these methods will allow you to do.
GI don't want to bring you into class on the first day, give you a list I
Gof supplies and then send you home early. So, let's take a look at the ?
star of our show and get a feel for what we are dealing with.
FBelow is a simple Applesoft program. It asks for a number, and prints I
that many dots, followed by a bell. Dumb, simple, but a quick example.
10 GET A
20 PRINT ".";
30 A = A - 1
40 IF A > 0 THEN 20
50 PRINT CHR$ (7)
60 END
FNow here is the same program written in assembly language. Whoa...you I
Gsay! Its twice as long and looks like greek. Ok...don't panic. (By the ?
=way, Hitchikers guide to the galaxy is recommended reading.) H
FEverything means something, and is intended to make your life easier. E
CFirst I'm going to label the parts, and then I'm going to describe
them.E
-------------------------------------------------------------------/
Line Argument9
Machine code # Labels Opcode RemarksE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -7
1 ********************************0
2 * Another useless program?
3 * But a fun example of assembly language7
4 ********************************
57
6 *-- Equates --------------------D
7 COUT EQU $FDED ;output a characterB
8 BELL EQU $FBDD ;beep the speaker@
9 STROBE EQU $C010 ;keyboard flags:
10 KEY EQU $C000 ;keyboard
117
12 *-- The program ----------------D
8000: 2C 10 C0 13 BIT STROBE ;clear the keyboard)
8003: AD 00 C0 14 GETKEY LDA KEYE
8006: 10 FB 15 BPL GETKEY ;wait for a keypress>
8008: 29 0F 16 AND #$0F ;ascii to hexC
800A: AA 17 TAX ;save the keypress*
800B: A9 AE 18 LDA #"."E
C800D: 20 ED FD 19 PRINT JSR COUT ;print a "." on the
screen#
8010: CA 20 DEX+
8011: D0 FA 21 BNE PRINT@
8013: 20 DD FB 22 JSR BELL ;sound the bell:
8016: 60 23 RTS ;and quit
--End assembly, 23 bytes, Errors: 0
Symbol table - alphabetical order:
D BELL =$FBDD COUT =$FDED GETKEY =$8003 KEY
=$C000'
PRINT =$800D STROBE =$C010
Symbol table - numerical order:
C GETKEY =$8003 PRINT =$800D KEY =$C000 STROBE
=$C010'
BELL =$FBDD COUT =$FDED
------------------------------------------------------------ -------H
FNow remember, these are brief descriptions, designed to introduce and E
Ctease you into the next class. We'll deal with each of these parts 1
until you are good and tired of them. Carry on.
"Machine Code"F
DThis is the actual code that the 65C02 understands and can use. The I
Gnumbers are all "hexadecimal," a big word we'll talk about a LOT more. C
AThe first four numbers before the colon is the address that this I
Ginformation will appear at. The pairs of numbers and letters after the A
?colon is the actual encoded data. This information is what the
assembler creates for us.
"Line Number"C
ASTRICTLY for the programmers convenience when editing. We do NOT @
>require lines to have numbers (as in BASIC) and in fact, some I
Gassemblers do not even produce these. Remember, these numbers are just
for you, the human.
"Labels"I
GThese are words, usually something like "COUT", or "START" or "GETLN". B
@These are locations given to the assembler that it can use when D
Bcomputing "addresses." These are an equivalent to line numbers in @
>BASIC. They can also be used to represent values, much like a B
@preassigned variable. (i.e. setting D$ equal to CHR$(4) for dos F
Dcommands.) Incidentally, any line that starts with an "*" (at least F
Dwhen using MERLIN) is recognized as a remark, just like applesloths
"Opcode"4
This is a verb. The action. "Do this." More later.
"Argument"G
EThis is information that is used by the opcode. It can be a location 2
or a chunk of data. Or a combination of the two.
"Remarks"H
FSomething that everyone could use more of. If you mail me source code H
Fwithout remarks, I will write your name down in the national registry E
Cof lousy programmers and send your name to a magazine subscription
service.
DSo there...that ought to at least get you started. Now, here's your
assignment.
>1) send me email telling me what a nice guy I am and that you
downloaded this stuff
2) post to the bulletin board any questions that you might have.
3) start thinking of a project you would like to work on.
Asta la vista, saranoya, farewell and this is the end of this segment.
...niemannross